package com.safeluck.scannerqcr.fragment.pager;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.safeluck.scannerqcr.R;
import com.safeluck.scannerqcr.fragment.msg.BaseBackFragment;

/**
 * ScannerQCR
 * Created by lzw on 2017/12/7. 13:59:09
 * 邮箱：632393724@qq.com
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */

public class DemoFragment extends BaseBackFragment implements View.OnClickListener {

    private static final java.lang.String DEMO_ARG = "de";
    private Toolbar mToolbar;
    private Button btn;
    private String arg;

    public static DemoFragment newInstance(String arg){
        Bundle bundle = new Bundle();
        bundle.putString(DEMO_ARG,arg);
        DemoFragment demoFragment = new DemoFragment();
        demoFragment.setArguments(bundle);
        return demoFragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        if (bundle != null){
            arg = bundle.getString(DEMO_ARG);
        }
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.demo_fragment,container,false);
        initView(view);
        return attachToSwipeBack(view);
    }

    private void initView(View view) {
        mToolbar = view.findViewById(R.id.toolbar);
        mToolbar.setTitle("DemoFragment");
        initToolbar(mToolbar);
        btn = view.findViewById(R.id.btn);
        btn.setOnClickListener(this);
    }

    @Override
    public void onLazyInitView(@Nullable Bundle savedInstanceState) {
        super.onLazyInitView(savedInstanceState);
        btn.setText(getString(R.string.fragment)+"_"+arg);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn:
                extraTransaction().startDontHideSelf(ViewDemoFragment.newInstance());
                break;
            default:
                break;
        }
    }
}
